package com.nineclock.document.controller;

import com.nineclock.api.document.PcDocumentControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.dto.DocFileHistoryDto;
import com.nineclock.document.service.DocFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class PcDocumentController implements PcDocumentControllerApi {

    @Autowired
    private DocFileService docFileService;

    @Override
    @GetMapping("/pagingFile")
    public Result<PageResult<DocFileDto>> getDocFileByPage(
            @RequestParam(value = "page") Integer page,
            @RequestParam(value = "pageSize") Integer pageSize,
            @RequestParam(value = "keyword", required = false) String keyword) {
        PageResult<DocFileDto> pageResult = docFileService.pagingFiles(page, pageSize, keyword);
        return Result.success(pageResult);
    }

    @Override
    @PutMapping("/{fileId}/{status}")
    public Result changeDocFileStatus(@PathVariable(value = "fileId") Long fileId, @PathVariable(value = "status") Short status) {
        System.out.println("fileId = " + fileId + ",   status = " + status);
        docFileService.changStatus(fileId, status);
        return Result.success(ResponseEnum.OK);
    }

    @Override
    @GetMapping("/history/{fileId}")
    public Result<List<DocFileHistoryDto>> getDocFileHistory(@PathVariable(value = "fileId") Long fileId) {

        List<DocFileHistoryDto> fileHistoryDtoList = docFileService.getDocFileHistory(fileId);

        return Result.success(fileHistoryDtoList);
    }
}
